package com.oa.demo.auth.controller;


import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.oa.demo.common.entity.ResultBean;
import com.oa.demo.common.exception.BaseAuthException;
import com.oa.demo.auth.service.ITRoleService;
import com.oa.demo.auth.entity.TRole;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kongbox
 * @version v1.0
 * @since 2020-11-27
 */
@RestController
@RequestMapping("//api/v1/t-role")
public class TRoleController {

    @Autowired
    private ITRoleService iTRoleService;

    /**
     * 查询分页数据
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResultBean<?> listByPage(@RequestParam(name = "page", defaultValue = "1") int page,
                                    @RequestParam(name = "pageSize", defaultValue = "10") int pageSize,
                                    @RequestParam(name = "factor", defaultValue = "") String factor) {
        return new ResultBean<>(iTRoleService.listTRolesByPage(page, pageSize, factor));
    }


    /**
     * 根据id查询
     */
    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    public ResultBean<?> getById(@PathVariable("id") Integer id) {
        return new ResultBean<>(iTRoleService.getTRoleById(id));
    }

    /**
     * 新增
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResultBean<?> insert(@RequestBody TRole tRole) throws BaseAuthException {
        return new ResultBean<>(iTRoleService.insertTRole(tRole));
    }

    /**
     * 删除
     */
    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    public ResultBean<?> deleteById(@PathVariable("id") Integer id) throws BaseAuthException {
        return new ResultBean<>(iTRoleService.deleteTRoleById(id));
    }

    /**
     * 修改
     */
    @RequestMapping(method = RequestMethod.PUT)
    public ResultBean<?> updateById(@RequestBody TRole tRole) throws BaseAuthException {
        return new ResultBean<>(iTRoleService.updateTRole(tRole));
    }
}
